package com.itboye.ihomebank.homefragment;

import java.util.Observable;
import java.util.Observer;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.SPUtils;

public class FuYongTwo extends BaseOtherActivity implements Observer {

	UserPresenter presenter;
	Button ok;
	private String trans_type;
	private String balance;
	private String to_account;
	private String uid;

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.ok:
			// presenter.fuyong();
			/**
			 * uid 是 用户id to_account 是 收款方帐号（手机号码） balance 是 金额（单位分） trans_type
			 */
			uid = SPUtils.get(this, null, SPContants.USER_ID, "") + "";
			to_account = getIntent().getStringExtra("phone");
			balance = getIntent().getStringExtra("money");
			presenter.zhuanzhang(uid, to_account, balance, "1");
			break;

		default:
			break;
		}
	}

	@Override
	protected int layout_id() {
		// TODO Auto-generated method stub
		return R.layout.activity_yongjinzhifu;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		// TODO Auto-generated method stub
		presenter = new UserPresenter(this);
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == UserPresenter.zhuanzhang_success) {
				ActivityFuYongOne.getContext().finish();
				ByAlert.alert(entity.getData());
				finish();
			} else if (entity.getEventType() == UserPresenter.zhuanzhang_fail) {
				ByAlert.alert(entity.getData());
			}
		}
	}

}
